package com.bi.autotest.operations.payprocessoperation;

import com.auto.base.OperateAppium;
import com.bi.autotest.operations.operations_open.PayProcessOpenOperation;
import com.bi.autotest.pages.page_open.PayProcessOpenPage;
import com.bi.autotest.pages.payprocesspage.VipCardPage;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
/**
 * 购买储值卡操作
 */
public class VipCardOperation extends OperateAppium {
    private PayProcessOpenPage payProcessOpenPage;
    private PayProcessOpenOperation payProcessOpenOperation;
    private VipCardPage vipCardPage;

    public VipCardOperation(AndroidDriver androidDriver) {
        super(androidDriver);
        vipCardPage = new VipCardPage(androidDriver);
        payProcessOpenPage=new PayProcessOpenPage(androidDriver);
        payProcessOpenOperation = new PayProcessOpenOperation(androidDriver);
    }
    /**
     * 购买储值卡100.00元
     */
    public boolean  buyStoreValueCard() {
        boolean b = vipCardPage.isLoginPage();
        print("进入会员卡页面是否成功：" + b);
        AndroidElement deposit = vipCardPage.getDeposit();
        deposit.click();
        sleep(2000);
        AndroidElement myDeposit = vipCardPage.getMyDeposit();
        myDeposit.click();
        sleep(2000);
        AndroidElement add = vipCardPage.getAdd();//点一次一张100元卡
        add.click();
        sleep(2000);
        AndroidElement payButton = vipCardPage.getPayButton();
        payButton.click();
        sleep(8000);
        payProcessOpenOperation.passWord();
        sleep(5000);
        boolean isPaySuccess = payProcessOpenPage.isExistWeiXinPaySuccessText();
        print("购买储值卡100.00元,微信是否支付成功的情况：" + isPaySuccess);
        switchAppContext();
        //微信支付成功页面点击完成按钮
        payProcessOpenPage.getWeiXinPayCompleteButton().click();
        sleep(3000);
        pressCloseButton();
        sleep(2000);
        pressCloseButton();
        sleep(2000);
        pressBackKey();
        sleep(2000);
        return isPaySuccess;
    }






    //进入会员卡页面
    public boolean LoginAccount() {
        //进入账目查询页面
        exePre();
        boolean isLoginPage = vipCardPage.isLoginPage();
        return isLoginPage;
    }

    public void exePre() {
        driver.findElementByXPath("//android.widget.TextView[@text='花鸟虫鱼测试01卡']").click();
        sleep(5000);
        System.out.println("打开收藏h5");
        switchH5_C_W(vipCardPage.CHECK_STORE);
    }

}
